//
//  RecommendCell.m
//  MedicineBox
//
//  Created by dllo on 15/9/26.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "RecommendCell.h"
#import "UIImageView+WebCache.h"
#import "DKNightVersion.h"
#import "CustomTap.h"

@interface RecommendCell ()<UIScrollViewDelegate>

@property (nonatomic, retain) UIScrollView *scrollV;

@end
@implementation RecommendCell

- (void)dealloc
{
    
    [_scrollV release];
    [super dealloc];
    
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.scrollV = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 5, [[UIScreen mainScreen] bounds].size.width, 160)];
        [self.contentView addSubview:_scrollV];
        [_scrollV release];
        
        
    }
    return self;
}

- (void)getArray:(NSArray *)array
{

    _scrollV.contentSize = CGSizeMake([[UIScreen mainScreen] bounds].size.width * (array.count / 3), 160);
    _scrollV.contentOffset = CGPointMake(0, 0);
    _scrollV.delegate = self;
    
    
    for (int i = 0; i < array.count; i++) {
        
        
        UIImageView *imageV = (UIImageView *)[self.contentView viewWithTag:160 + i];
        if (imageV == nil) {
            
            imageV = [[UIImageView alloc] initWithFrame:CGRectMake(10 * (i + 1) + ([[UIScreen mainScreen] bounds].size.width - 30) / 3 * i, 5, ([[UIScreen mainScreen] bounds].size.width - 30) / 3, 100)];
            imageV.tag = 160 + i;
            imageV.userInteractionEnabled = YES;
            [_scrollV addSubview:imageV];
            [imageV release];
            
            CustomTap *tap = [[CustomTap alloc] initWithTarget:self action:@selector(tapAction:)];
            tap.dic = [array objectAtIndex:i];
            [imageV addGestureRecognizer:tap];
            [tap release];
            
        }
       
        [imageV sd_setImageWithURL:[NSURL URLWithString:[[array objectAtIndex:i] objectForKey:@"imgUrl"]]];
        
        
        UILabel *titleLabel = (UILabel *)[self.contentView viewWithTag:260 + i];
        if (titleLabel == nil) {
            
            titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(imageV.frame.origin.x, imageV.frame.origin.y + imageV.frame.size.height + 5, imageV.frame.size.width, 20)];
            titleLabel.tag = 260 + i;
           [_scrollV addSubview:titleLabel];
            [titleLabel release];
        }
        titleLabel.font = [UIFont systemFontOfSize:10];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.text = [[array objectAtIndex:i] objectForKey:@"name"];
        
        titleLabel.nightTextColor = [UIColor whiteColor];
        
    }
   
 

}

- (void)tapAction:(CustomTap *)tap
{

    [(NSObject *)self.target performSelector:self.action withObject:tap.dic];

}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
